package com.example.newspublish.util.result;

import lombok.Data;

import java.io.Serializable;

@Data
public class Result <T> implements Serializable {

    private boolean success; // 布尔判断是否成功
    private String message; // 字符串类型的消息
    private int code; // 返回码
    private T data; // 数据

    // 构造方法
    public Result(boolean success, String message, int code, T data) {
        this.success = success;
        this.message = message;
        this.code = code;
        this.data = data;
    }

    public Result() {

    }

    public static <T> Result<T> failed(int code, String msg) {
        return new Result(false, msg, code, null);
    }

    public static <T> Result<T> error(String msg) {
        Result result = new Result();
        result.message = msg;
        result.code = 0;
        return result;
    }

    public static <T> Result<T> success(String msg,T data) {
        return new Result(true , msg, 20000, data);
    }

    public static <T> Result<T> success() {

        return new Result(true, null, 20000, null);
    }

}
